<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS实现类似：hover效果</title>
</head>

<body>


    <h2>JS实现类似：hover效果</h2>
    <ul id="element">
        <li>手写</li>
        <li>拼音</li>
        <li id="close" onclick="close()">关闭</li>
    </ul>
    <style>
        .active {
            background-color: rgba(0, 0, 0, .3);
        }
    </style>

    <script>
        var btn = document.getElementById('btn')
        var li = document.getElementsByTagName('li')
        for (var i = 0; i < li.length; i++) {
            li[i].onmouseover = function () {
                for (var j = 0; j < li.length; j++) {
                    li[j].classList.remove('active')
                }
                this.classList.add('active')
            }
            li[i].onmouseleave = function () {
                this.classList.remove('active')
            }

        }

    </script>
</body>

</html>